package cn.caipengbo.helloandroid;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

public class MenuActivity extends AppCompatActivity {
    private Button buttonShow;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);
        buttonShow = (Button) findViewById(R.id.btn_longshow);
        buttonShow.setOnCreateContextMenuListener(this);
    }
    // 长按显示 —— ContextMenu
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        menu.add(0, 1, 0, "Item1" );
        menu.add(0, 2, 0, "Item2" );
        super.onCreateContextMenu(menu, v, menuInfo);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case 1: {

                break;
            }
            case 2: {

                break;
            }
            default: {
                break;
            }
        }
        return super.onContextItemSelected(item);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, 1, 0, "添加" );
        menu.add(0, 2, 0, "删除" );
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case 1: {

                break;
            }
            case 2: {

                break;
            }
            default: {
                break;
            }
        }
        return super.onOptionsItemSelected(item);
    }

}
